<template>
  <!-- 附件采购额及返利查询 -->
  <div>
    <TopFilter :list="attachmentTopFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="table"
      :dataSource="tableDataList"
      columnsRef="waxAttachmentFormA"
      :columns="columns"
      :onColumnsChange="columns => (this.columns = columns)"
      :onEnterEvent="doubleClick"
      :isSelectColumn="false"
      :isMemoryPagination="true"
      :isExportExcel="true"
      exportFileName="附件采购额及返利查询.xlsx"
    >
      <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-daochu" :disabled="exportBtn" @click="handleExport">导出</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-printer" :disabled="printBtn" @click="handlePrint">打印</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-plus" @click="publishInfo">新建</el-button>
        <AjaxButton :click="pushDialog" type="primary">发布</AjaxButton>
        <AjaxButton :click="offlineDialog" type="primary">下线</AjaxButton> -->
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="visible" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <AttachDoubleClick :PERIOD="PERIOD" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getAttachment, getDoubleAttachment, getExcelList } from '@/api/part/report/attachmentQuery';
import AttachDoubleClick from './attachDoubleClick';
import { exportExcelFile } from '@/utils/index';
import moment from 'moment';
export default {
  name: 'AttachmenQuery',
  components: { AttachDoubleClick },
  mixins: [dictionary],
  props: [],
  data() {
    return {
      attachmentTopFilterList: this.createAttachmentTopFilterList(),
      columns: this.createTableList(),
      fetchParams: { xhrAbort: true },
      fetchApi: getAttachment,
      exportBtn: false,
      printBtn: false,
      visible: false,
      dialogTitle: '明细',
      PERIOD: {},
      condition: [],
      tableDataList: [], // table数据
      queryParam: {}
    };
  },
  created() {
    // this.handleTableSearch();
  },
  methods: {
    // 双击处理
    doubleClick(val) {
      console.log(val);
      this.PERIOD = val.SPBUP;
      this.visible = true;
    },
    // 打印处理
    handlePrint() {},
    // 导出处理
    handleExport() {
      const option = {};
      console.log('查询参数', this.fetchParams);

      getExcelList(this.queryParam).then(response => {
        console.log(response, '附件采购额及返利查询');
        exportExcelFile(response.data, '附件采购额及返利查询');
        // this.exportLoading = false;
        // this.exportExcel(res.records);
      });
    },
    // 展开收起调用函数
    collapseHandle() {},
    // 搜索条件改变调用方法
    async changeHandle(val) {
      this.$refs.table.START_LOADING();
      this.queryParam = val;
      let res = await getAttachment({
        ...val
      });
      this.$refs.table.STOP_LOADING();

      if (res.resultCode == 200) {
        this.tableDataList = res.data.IT_CGE_QUERY;
      }
    },
    // 创建表单字段列表
    createTableList() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          dataIndex: 'KUNNR',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'NAME1',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '年月',
          dataIndex: 'SPBUP',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          filterItems: []
        }
      ];
    },
    // 关闭操作
    closeHandler() {
      this.visible = false;
    },
    // 创建筛选条件
    createAttachmentTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '财政期间',
          dateFormat: 'yyyyMM',
          fieldName: 'I_PERIOD1|I_PERIOD2',
          initialValue: [
            moment()
              .startOf('month')
              .format('YYYY-MM-DD'),
            moment().format('YYYY-MM-DD')
          ],
          placeholder: '',
          rules: [{ required: true, message: '请选择财政期间', trigger: 'blur' }]
        }
      ];
    }
  }
};
</script>

<style></style>
